package org.blogwu.learn.multithread.juc.queue;

import java.util.concurrent.SynchronousQueue;

public class SynchronousQueueTest {

    static final SynchronousQueue<String> queue=new SynchronousQueue<>();

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            try {
                Thread.sleep(20000);
                System.out.println(queue.take());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        });
        Thread t2 = new Thread(()->{
            try {
                queue.put("Hello");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("t2 over");

        });
        Thread t3 = new Thread(()->{
            try {
                Thread.sleep(10000);
                System.out.println(queue.take());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        });
        Thread t4 = new Thread(()->{
            try {
                queue.put("world!");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("t4 over");

        });
        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t1.join();
        t2.join();
        t3.join();
        t4.join();

    }



}
